import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ContractVO, ContractForm, ContractQuery } from '@/api/goods/contract/types';

/**
 * 查询合同列表
 * @param query
 * @returns {*}
 */

export const listContract = (query?: ContractQuery): AxiosPromise<ContractVO[]> => {
  return request({
    url: '/order/contract/list',
    method: 'get',
    params: query
  });
};
/**
 * 查询合同统计
 * @param query
 * @returns {*}
 */

export const getContractCount = (query?: ContractQuery): AxiosPromise<ContractVO[]> => {
  return request({
    url: '/order/contract/listCount',
    method: 'get',
    params: query
  });
};
/**
 * 生成合同编号
 * @param query
 * @returns {*}
 */

export const getContractNumber = (): AxiosPromise<ContractVO[]> => {
  return request({
    url: '/order/contract/getContractNumber',
    method: 'get',
  });
};

/**
 * 查询合同详细
 * @param id
 */
export const getContract = (id: string | number): AxiosPromise<ContractVO> => {
  return request({
    url: '/order/contract/' + id,
    method: 'get'
  });
};

/**
 * 新增合同
 * @param data
 */
export const addContract = (data: ContractForm) => {
  return request({
    url: '/order/contract',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同
 * @param data
 */
export const updateContract = (data: ContractForm) => {
  return request({
    url: '/order/contract',
    method: 'put',
    data: data
  });
};

/**
 * 删除合同
 * @param id
 */
export const delContract = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/contract/' + id,
    method: 'delete'
  });
};

export default {
  list:listContract,


  get:getContract,

  add:addContract,

  update:updateContract,
  del: delContract,
  getContractNumber,
  getContractCount
}